package LeetCode.剑指Offer._220530._2021春赛题集;

import java.util.Arrays;

/**
 * @Author: yqy
 * @Date: 2022/05/30/21:58
 * @Description:采购方案
 */
public class _28 {
    public int purchasePlans(int[] nums, int target) {
        Arrays.sort(nums);
        int price=0;
        for(int i=0;i<nums.length;i++){
            int temp=target-nums[i];
            int j=nums.length-1;
            while(i<j){
                if(temp<nums[j]){
                    continue;
                }
                j--;
            }
            price +=(j-i);
        }
        return price;
    }
    public int purchasePlansPlus(int[] nums, int target) {
        Arrays.sort(nums);
        int price=0;
        for(int i=0;i<nums.length;i++){
            int temp=target-nums[i];
            int j=nums.length-1;
            while(i<j){
                if(temp<nums[j]){
                    continue;
                }
                j--;
            }
            price +=(j-i);
        }
        return price;
    }
}
